// 1356.h : main header file for the 1356 DLL
//

#pragma once

#ifndef __AFXWIN_H__
	#error "include 'stdafx.h' before including this file for PCH"
#endif

#include "resource.h"		// main symbols

typedef CString FlashData;
typedef CString CSData;

typedef CString ReadingMemory;
//typedef ReadingMemory PReadingMemory;



#define FUNCTIONEXCUTING 1111
#define NOTYETRESET 1001 // Close and then open again
#define SUCCESSED 1000

//************************************

#define RWD_TX_BUFFER_SIZE	128
#define RWD_RX_BUFFER_SIZE	256
#define DATABITS	12

//register D11  - lenh khan - reset
#define NONE		906
#define RESET_X		907	
#define RESET_Y		908
#define RESET_Z		909
#define RESET_XYZ	910	
#define EMERGENCY	905
#define HOLD		911
#define CONTINUE	912

// register D9 , D995  - kind of robot
#define RTV	921
#define AGV	922
#define SR	923
#define ALL	924


//register D996  -- thong bao trang thai
#define FINISHED		950 // da hoan thanh
#define WORKING			951 // dang hoan thanh
#define ERR_TRANSMIT	952 // error transmit
#define ERR_SYSTEM		953 // loi he thong
#define REFERENCE		954 // chua ve diem chuan
#define ERR_COMMAND		955// loi sai lenh
#define ERR_RECEIVE		956 // loi nhan khong du 12bytes

/*****************************************************/

#define b3b2b1b0		15	


class CMy1356App : public CWinApp
{
public:
	CMy1356App();

// Overrides
public:
	virtual BOOL InitInstance();

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
#undef AFX_DATA
#define AFX_DATA AFX_EXT_DATA

	int CharToHex(char c); 
	unsigned char ByteToChar(DWORD dwByte);
	BYTE CharToByte(unsigned char cChar);
	int CharToInt(unsigned char cChar);

	void CharToString(byte cData[64], CString* csData);
	void CStringToChar(CString csData, char cChar[64]);
	int Login(int iID_RFID);
	int Logout(int iID_RFID);
	int SetKey(byte bKeyA[6], int iKeyAIndex, byte bKeyB[6], int iKeyBIndex) ;
	int GetKey(byte bKeyA[6], int *iKeyAIndex, byte bKeyB[6], int *iKeyBIndex) ;
	int ModulPlate(byte cPlate[64], byte cPlateOut[64]);
	int TransferCommand(CString * csTransmit, char cNode, char cCode, char cParameter[64]);

	extern "C" void PASCAL EXPORT RS_Open(int *iStatus);
	extern "C" void PASCAL EXPORT RS_Close(int *iStatus);
    extern "C" int PASCAL EXPORT Tran_Rec( int iDevice, int* iFlag, CString* csTransmit, CString* csReceive);  // send data and return status
	extern "C" int PASCAL EXPORT Modul(DWORD dEmergency,DWORD dRobot,DWORD dCommand,DWORD dPOS_SR ,DWORD dPosition , CString* csData, DWORD* dReturn);  
	

	void CStringToChar(CString csData, char cChar[64]);
	
//	bool Open; // Flag which indicates at all time whether or not the serial port is open
	/*************************Communication Reader and PC***********************/

	extern "C" int PASCAL EXPORT init_rfid( int iID_RFID);

	extern "C" int PASCAL EXPORT getUID(int  iID_RFID, char cUID[64]);
	
	extern "C" int PASCAL EXPORT get_plate(int  iID_RFID,char  cPlate_Number[64], char csTime_Info[64], char csDriver[64], 
char csVehicle[128]); 

	extern "C" int PASCAL EXPORT write_plate(int  iID_RFID, char cPlate_Number[64], char cTime_Info[64], char cDriver[64], 
char cVehicle[64]);

	extern "C" int PASCAL EXPORT init_Cam( int iID_Cam);

	extern "C" int PASCAL EXPORT get_image( int iID_Cam, bool* Plate_Flag, char Image[64],int* iCorrect, int* iTime, char Time[64], char Plate_number[64], 
char Vehicle[64]);
	

	



#undef AFX_DATA
#define AFX_DATA
